package com.im.foodorderingsystem;

import com.im.foodorderingsystem.task.RegistrationTask;

import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.os.Build;

public class Registration extends ActionBarActivity {

	EditText etFirstName;
	EditText etLastName;
	EditText etPhoneNumber;
	
	EditText etCity;
	EditText etEmail;
	EditText etPassword;
	EditText etConfirmPassword;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_registration);

		etFirstName=(EditText)findViewById(R.id.etFirstName);
		
		etEmail=(EditText)findViewById(R.id.etEmail);
		etPassword=(EditText)findViewById(R.id.etRegPassword);
		etConfirmPassword=(EditText)findViewById(R.id.etRegConfirmPassword);

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {

		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.registration, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	public void register(View v){
		int error=0;	//flag
		
		String firstName=etFirstName.getText().toString();
		String email=etEmail.getText().toString();
		String password=etPassword.getText().toString();
		String confirmPassword=etConfirmPassword.getText().toString();
		

		if(firstName.equals("")){
			error=1;
			etFirstName.setError("Please Fill");
		}
		
		if(email.equals("")){
			error=1;
			etEmail.setError("Please Fill");
		}
		if(password.equals("")){
			error=1;
			etPassword.setError("Please Fill");
		}
		if(confirmPassword.equals("")){
			error=1;
			etConfirmPassword.setError("Please Fill");
		}
		
		if(!email.equals("") && !confirmPassword.equals("") && !password.equals(confirmPassword)){
			error=1;
			etPassword.setError("Invalid Password Confirmation");
			etConfirmPassword.setError("Invalid Password Confirmation");
		}
		
		if(error==0){
			String [] parameters;
			parameters=new String[3];
			parameters[0]=email;
			parameters[1]=password;
			parameters[2]=firstName;
			
			
			RegistrationTask registrationtask=new RegistrationTask(this);
			registrationtask.execute(parameters);
		}
	}

}
